using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.IO;
namespace HouseControl
{
    class Settings
    {
        public static void SettingsPageIndex(object sender, EventArgs evt)
        {
            if (Program.SettingsSet != null)
            {
                Program.SettingsSet.Close();
                Program.SettingsSet = null;
                Program.CheckingsPage();
            }
            else if (Program.SettingsSet == null)
            {
                Program.mainWindow.Close();
                Program.mainWindow = null;
                SettingsPage();
            }

        }

        public static void Settings_heatIndex(object sender, EventArgs evt)
        {
            if (Program.Settings_heat != null)
            {
                Program.Settings_heat.Close();
                Program.Settings_heat = null;
                SettingsPage();
            }
            else if (Program.Settings_heat == null)
            {
                Program.SettingsSet.Close();
                Program.SettingsSet = null;
                Settings_heatPage();
            }

        }


        public static void Settings_helpIndex(object sender, EventArgs evt)
        {
            if (Program.Settings_help != null)
            {
                index = 0;
                Program.Settings_help.Close();
                Program.Settings_help = null;
                SettingsPage();
            }
            else if (Program.Settings_help == null)
            {
                Program.SettingsSet.Close();
                Program.SettingsSet = null;
                
                Settings_helpPage();
            }

        }

       public static int index = 0;  //index helps us to know which help page is currently displayed
        public static void inc(object sender, EventArgs e)  //increase the value of the index each  time someone press on the Help Pages
        {
            if(index>=0 && index < 4) index++; //the index must be between 0 and 3 because we have 5 pages for the Help Menu
            Settings_helpPage();  //once the index is incremented the we return to the Help Page to display the next Help's Page
        }

        public static Window Settings_helpPage()
        {
            Program.Settings_help = new Window();
            Program.Settings_help.Height = SystemMetrics.ScreenHeight;
            Program.Settings_help.Width = SystemMetrics.ScreenWidth;
            StackPanel stackPanel = new StackPanel();

            if (index == 0)
            {
                Image i1 = new Image(Resources.GetBitmap(Resources.BitmapResources.help1));
                SimpleButton i1Button = new SimpleButton(i1, Program.Settings_help.Width, 205);
                //when someone press on this page then the index is incremented and then the window is reloaded with the next page
                i1Button.Click += new EventHandler(inc); 
                stackPanel.Children.Add(i1Button);

            }
            else if (index == 1)
            {

                Image i11 = new Image(Resources.GetBitmap(Resources.BitmapResources.help11));
                SimpleButton i11Button = new SimpleButton(i11, Program.Settings_help.Width, 205);
                //same thing as above
                i11Button.Click += new EventHandler(inc);
                stackPanel.Children.Add(i11Button);

            }
            else if (index == 2)
            {
               
                Image i2 = new Image(Resources.GetBitmap(Resources.BitmapResources.help2));
                SimpleButton i2Button = new SimpleButton(i2, Program.Settings_help.Width, 205);
                //same thing as above
                i2Button.Click += new EventHandler(inc);
                stackPanel.Children.Add(i2Button);
              
            }
            else if (index == 3)
            {

                Image i3 = new Image(Resources.GetBitmap(Resources.BitmapResources.help3));
                SimpleButton i3Button = new SimpleButton(i3, Program.Settings_help.Width, 205);
                //Same thing as above
                i3Button.Click += new EventHandler(inc);
                stackPanel.Children.Add(i3Button);

            }

            else if (index == 4)
            {

                Image i4 = new Image(Resources.GetBitmap(Resources.BitmapResources.help4));
                SimpleButton i4Button = new SimpleButton(i4, Program.Settings_help.Width, 205);
                
                stackPanel.Children.Add(i4Button);

            }

          
                Image back = new Image(Resources.GetBitmap(Resources.BitmapResources.back2));
                SimpleButton backButton = new SimpleButton(back, Program.Settings_help.Width, 43);
                backButton.Click += new EventHandler(Settings_helpIndex);
                stackPanel.Children.Add(backButton);
            
            Program.Settings_help.Child = stackPanel;
            stackPanel.SetMargin(0, 0, 00, 0);
            Program.Settings_help.Visibility = Visibility.Visible;

            return Program.Settings_help;
        }

        public static Window Settings_heatPage()
        {
            Program.Settings_heat = new Window();
            Program.Settings_heat.Height = SystemMetrics.ScreenHeight;
            Program.Settings_heat.Width = SystemMetrics.ScreenWidth;
            Canvas canvas = new Canvas();

           //diplay "Heat Control"
            Text text = new Text();
            text.Font = Resources.GetFont(Resources.FontResources.NinaB);
            text.TextContent = Resources.GetString(Resources.StringResources.String1);
            text.ForeColor = Colors.Red;
            Canvas.SetTop(text, 5);
            Canvas.SetRight(text, 100);
            canvas.Children.Add(text);

            //display "Minimum"
            Text maximum_temp = new Text();
            maximum_temp.Font = Resources.GetFont(Resources.FontResources.NinaB);
            maximum_temp.ForeColor = Colors.Blue;
            maximum_temp.TextContent = "Minimum";
            Canvas.SetTop(maximum_temp, 25);
            Canvas.SetLeft(maximum_temp, 10);

            canvas.Children.Add(maximum_temp);

            //display "Maximum"
            Text minimum_temp = new Text();
            minimum_temp.Font = Resources.GetFont(Resources.FontResources.NinaB);
            minimum_temp.ForeColor = Colors.Blue;
            minimum_temp.TextContent = "Maximum";
            Canvas.SetTop(minimum_temp, 25);
            Canvas.SetRight(minimum_temp, 10);
            canvas.Children.Add(minimum_temp);

            //"+" Button to increase Temperature Max
            Text plus_max = new Text();
            plus_max.Font = Resources.GetFont(Resources.FontResources.NinaB);
            plus_max.ForeColor = Color.White;
            plus_max.TextAlignment = TextAlignment.Center;
            plus_max.VerticalAlignment = VerticalAlignment.Center;
            plus_max.TextContent = "+";
            //insert the text in the bouton
            SimpleButton plus_maxButton = new SimpleButton(plus_max, 20, 30);
            Canvas.SetTop(plus_maxButton, 37);
            Canvas.SetRight(plus_maxButton, 10);
            canvas.Children.Add(plus_maxButton);
            plus_maxButton.Click += new EventHandler(Heat_Control.increase_max_temperature);


            //"+" Button to increase Temperature Min
            Text plus_min = new Text();
            plus_min.Font = Resources.GetFont(Resources.FontResources.NinaB);
            plus_min.ForeColor = Color.White;
            plus_min.TextAlignment = TextAlignment.Center;
            plus_min.VerticalAlignment = VerticalAlignment.Center;
            plus_min.TextContent = "+";
            //insert the text in the Button
            SimpleButton plus_minButton = new SimpleButton(plus_min, 20, 30);
            Canvas.SetTop(plus_minButton, 37);
            Canvas.SetLeft(plus_minButton, 10);
            canvas.Children.Add(plus_minButton);
            plus_minButton.Click += new EventHandler(Heat_Control.increase_min_temperature);

            // Box to display Max Temperature
            Text Box_Max = new Text();
            Box_Max.Font = Resources.GetFont(Resources.FontResources.NinaB);
            Box_Max.ForeColor = Colors.Red;
            Box_Max.TextAlignment = TextAlignment.Center;
            Box_Max.VerticalAlignment = VerticalAlignment.Center;
            Box_Max.TextContent = "" + Program.max_temp.ToString();
            //insert the text in the bouton
            SimpleButton Box_MaxButton = new SimpleButton(Box_Max, 20, 30);
            Canvas.SetTop(Box_MaxButton, 62);
            Canvas.SetRight(Box_MaxButton, 10);
            canvas.Children.Add(Box_MaxButton);

            // Box to display Min Temperature
            Text Box_Min = new Text();
            Box_Min.Font = Resources.GetFont(Resources.FontResources.NinaB);
            Box_Min.ForeColor = Colors.Red;
            Box_Min.TextAlignment = TextAlignment.Center;
            Box_Min.VerticalAlignment = VerticalAlignment.Center;
            Box_Min.TextContent = "" + Program.min_temp.ToString();
            //insert the text in a button
            SimpleButton Box_MinButton = new SimpleButton(Box_Min, 20, 30);
            Canvas.SetTop(Box_MinButton, 62);
            Canvas.SetLeft(Box_MinButton, 10);
            canvas.Children.Add(Box_MinButton);




            //"-" Button to decrease Temperature Max
            Text minus_max = new Text();
            minus_max.Font = Resources.GetFont(Resources.FontResources.NinaB);
            minus_max.ForeColor = Color.White;
            minus_max.TextAlignment = TextAlignment.Center;
            minus_max.VerticalAlignment = VerticalAlignment.Center;
            minus_max.TextContent = "-";
            //insert the text in a button
            SimpleButton minus_maxButton = new SimpleButton(minus_max, 20, 30);
            Canvas.SetTop(minus_maxButton, 92);
            Canvas.SetRight(minus_maxButton, 10);
            canvas.Children.Add(minus_maxButton);
            minus_maxButton.Click += new EventHandler(Heat_Control.decrease_max_temperature);



            //"-" Button to decrease Temperature Min
            Text minus_min = new Text();
            minus_min.Font = Resources.GetFont(Resources.FontResources.NinaB);
            minus_min.ForeColor = Color.White;
            minus_min.TextAlignment = TextAlignment.Center;
            minus_min.VerticalAlignment = VerticalAlignment.Center;
            minus_min.TextContent = "-";
            //insert the text in a button
            SimpleButton minus_minButton = new SimpleButton(minus_min, 20, 30);
            Canvas.SetTop(minus_minButton, 92);
            Canvas.SetLeft(minus_minButton, 10);
            canvas.Children.Add(minus_minButton);
            minus_minButton.Click += new EventHandler(Heat_Control.decrease_min_temperature);



                Image back = new Image(Resources.GetBitmap(Resources.BitmapResources.back2));
                SimpleButton backButton = new SimpleButton(back, 400, 25);
                
                Canvas.SetBottom(backButton, 10);
                canvas.Children.Add(backButton);
                backButton.Click += new EventHandler(Settings_heatIndex);
            

             //display an image in background
            ImageBrush background = new ImageBrush(Resources.GetBitmap(Resources.BitmapResources.Background));
            background.Stretch = Stretch.Fill;
            Program.Settings_heat.Background = background;


            // Add the text control to the window.
            Program.Settings_heat.Child = canvas;

            Program.Settings_heat.Visibility = Visibility.Visible;


            return Program.Settings_heat;
        
        }

        public static void theme_changer(object sender, EventArgs evt)
        {
            Program.theme_changed = !(Program.theme_changed); //change the theme
            if (Program.SettingsSet != null)
            {
                Program.SettingsSet.Close();
                Program.SettingsSet = null;
                Program.CheckingsPage();
            }
            else if (Program.SettingsSet == null)
            {
                Program.mainWindow.Close();
                Program.mainWindow = null;
                SettingsPage();
            }
        }


        public static Window SettingsPage()
        {
            Program.SettingsSet = new Window();
            Program.SettingsSet.Height = SystemMetrics.ScreenHeight;
            Program.SettingsSet.Width = SystemMetrics.ScreenWidth;
            StackPanel stackPanel = new StackPanel();


          
                Image theme_switch = new Image(Resources.GetBitmap(Resources.BitmapResources.theme_changing1));
                SimpleButton theme_switchButton = new SimpleButton(theme_switch, Program.SettingsSet.Width, 43);
                theme_switchButton.Click += new EventHandler(theme_changer);

                Image setMaxMin = new Image(Resources.GetBitmap(Resources.BitmapResources.theme_changing11));
                SimpleButton setMaxMinButton = new SimpleButton(setMaxMin, Program.SettingsSet.Width, 43);
                setMaxMinButton.Click += new EventHandler(Settings_heatIndex);

                Image help = new Image(Resources.GetBitmap(Resources.BitmapResources.theme_changing12));
                SimpleButton helpButton = new SimpleButton(help, Program.SettingsSet.Width, 43);
                helpButton.Click += new EventHandler(Settings_helpIndex);

                Image back = new Image(Resources.GetBitmap(Resources.BitmapResources.back2));
                SimpleButton backButton = new SimpleButton(back, Program.SettingsSet.Width, 43);
                backButton.Click += new EventHandler(SettingsPageIndex);

                stackPanel.Children.Add(theme_switchButton);
                stackPanel.Children.Add(setMaxMinButton);
                stackPanel.Children.Add(helpButton);
                stackPanel.Children.Add(backButton);
            

            Program.SettingsSet.Child = stackPanel;
            stackPanel.SetMargin(0, 0, 00, 0);
            Program.SettingsSet.Visibility = Visibility.Visible;


            return Program.SettingsSet;
        }
    }
}
